﻿using Autodesk.AutoCAD.Runtime;
using Autodesk.Windows;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using static Autodesk.AutoCAD.Internal.LayoutContextMenu;
using static System.Net.Mime.MediaTypeNames;

namespace CAD.Ribbon
{
    public class RibbonClass
    {
        public static string assemblyPath = Assembly.GetExecutingAssembly().Location;
        public static string assemblyDir = Path.GetDirectoryName(assemblyPath) + "\\";


        [CommandMethod("RibbonDemo")]
        public void RibbonDemo()
        {
            RibbonControl ribbonControl = ComponentManager.Ribbon;
            RibbonTab ribbonTab = ribbonControl.AddTab("ribbon", Guid.NewGuid().ToString(), true);

            RibbonPanelSource panelSource = ribbonTab.AddPanel("first panel");



            RibbonButton ribbonButton1 =
            RibbonService.GenRibbonButton("name1", "text1", "Line",
                new RibbonCommandHandler(),
                RibbonService.GenImageSource(Resource.ICON_ALL));
            panelSource.Items.Add(ribbonButton1);


            RibbonButton ribbonButton2 =
                RibbonService.GenRibbonButton("name2", "text2", "Line",
                  new AcadCommandHandler(), RibbonService.GenImageSource(Resource.ICON_ALL));
            panelSource.Items.Add(ribbonButton2);


            //按下按钮时加载指定dll内功能
            var dllPath = Path.Combine(assemblyDir, "CAD.Demo.dll");
            RibbonButton ribbonButton3 =
                RibbonService.GenRibbonButton("name3", "text3", " ",
                  new LoadDllCommandHandler(dllPath, "CAD.Demo.HelloCommand", "ShowWpfView"),
                                RibbonService.GenImageSource(Resource.ICON_ALL));
            panelSource.Items.Add(ribbonButton3);



        }



        [Autodesk.AutoCAD.Runtime.CommandMethod("AddMyPaletteSet")]
        public void AddMyPaletteSet() 
        { 
            Autodesk.AutoCAD.Windows.PaletteSet myPaletteSet 
                = new Autodesk.AutoCAD.Windows.PaletteSet("我的PallteSet");

            myPaletteSet.Add("我的工具集", new System.Windows.Forms.Control("我的工具集")); 
            myPaletteSet.Add("我的颜色", new System.Windows.Forms.Control("我的颜色")); 
            myPaletteSet.Add("我的控件", new System.Windows.Forms.Control("我的控件"));
             
            myPaletteSet.Visible = true; 
        }

    }




}
